import 'package:dio/dio.dart';

import '../widgets/common/jzx_toast.dart';
import 'jzx_api_client.dart';
import 'jzx_interceptor.dart';

export 'jzx_bp_repository.dart';

/// 统一处理错误信息
void formatError(e) {
  // logger.d(e.toString());
  if (e is Response) {
    JzxToast.showError(e.statusMessage ?? '');
    return;
  }
  JzxToast.showError('请求异常');
}

class JzxNetRepository {
  /// 请求体 (如果域名不一致可以创建多个请求体进行区分)
  static ApiClient client = ApiClient(
    Dio(BaseOptions())
      ..interceptors.addAll([
        LogInterceptor(
          requestBody: true,
          responseBody: true,
        ),
        JzxNetInterceptor(),
      ]),
    baseUrl: appDomain.host,
  );

    static ApiClient bpClient = ApiClient(
    Dio(BaseOptions())
      ..interceptors.addAll([
        LogInterceptor(
          requestBody: true,
          responseBody: true,
        ),
        JzxNetInterceptor(),
      ]),
    baseUrl: appDomain.bpHost,
  );
}

final appDomain = AppDomain(
  host: 'http://test-app.cosmofusionly.xyz/',
  bpHost: 'http://log.cosmofusionly.xyz/',
);

class AppDomain {
  /// 接口域名
  final String host;

  /// 埋点
  final String bpHost;

  /// final String host1;
  /// final String host2;
  /// ...

  AppDomain({
    required this.host,
    required this.bpHost,
  });
}
